#!/bin/bash

# Loading configuration
if [ -f ${CASPER_CONF_DIR}/casperd.conf ]; then
	source ${CASPER_CONF_DIR}/casperd.conf
fi

cd $1

RENDER_XML=`find . -name yafarayRender.xml`

# Moving all textures
TEXTURES=`find . -iname '*.png' -or -iname '*.jpg' -or -iname '*.gif' -or -iname '*.tga'`
mkdir textures
for texture in $TEXTURES
do
	if [ $texture != ${TEXTURES_PATH}`basename $texture` ]; then
		mv $texture ${TEXTURES_PATH}`basename $texture | tr A-Z a-z`
	fi
done

if [ ! -f ./yafarayRender.xml ]; then
	mv ${RENDER_XML} ./yafarayRender.xml
fi

${CASPER_ROOT_DIR}/plugins/render/yafaray-xml-cut.sh yafarayRender.xml ${NODES_NUMBER} 1 &
echo "jobs ${JOB_ID} process $!"
wait $!
EXIT_STATUS=$?
if [ $EXIT_STATUS -ne 0 ]; then
	exit $EXIT_STATUS
fi
